<template>
    <view class="container">
        <template v-for="(activity,activityIndex) in activityObj.list">
            <view class="activityItem" :key="activity.id" @click="gotoLottery(activity)">
                <image :src="activity.cover" class="top" mode=""></image>

                <view class="bottom">
                    <view class="left">
                        <view class="title text-1line-ellipsis">
                            {{activity.name}}
                        </view>

                        <view class="timeOut" v-if="activity.activityStatus==0">
                            活动开始时间：{{activity.startTime}}
                        </view>
                                                                   
                        <view class="timeOut" v-else-if="activity.activityStatus==1">
                            活动截至时间：{{activity.endTime}}
                        </view>
                        
                        <view class="timeOut" v-else>
                            活动已结束
                        </view>
                    </view>
                    <view class="right">
                        <view v-if="activity.activityStatus==0||activity.activityStatus==1" class="status statusEn" >
                            {{activity.activityStatusName}}
                        </view>
                        <view v-else class="status statusDis">
                            {{activity.activityStatusName}}
                        </view>                       
                    </view>
                </view>
            </view>
        </template>
        <view class="" style="height: 150rpx;">
            
        </view>
    
    </view>
</template>

<script>
    let timeId = null
    const api = require('@/static/js/api.js')
    const utils = require("@/static/js/utils.js")

    let that = null
    export default {
        data() {
            return {

                activityObj:{
                    list:[],
                    loadStatus:"loading",
                    pageIndex: 1,
					curPageIndex:0,
                }
            };
        },

        components: {
            
        },
        props: {
            value: {
                type: Boolean,
                default: false,
            },
        },

        onLoad() {
            that = this;
            that.getActivityList()
        },

        onReachBottom() {
            that.getActivityList()    
        },

        methods: {
            getActivityList(){
				if (that.activityObj.curPageIndex != that.activityObj.pageIndex){
					that.activityObj.curPageIndex = that.activityObj.pageIndex
					api.getActivityList({
					    param:{
					        limit:5,
					        page: that.activityObj.pageIndex,
					    }
					}).then(res=>{
					    console.log("ActivityList:",res)
					    if (res.code==0){
					        that.pushListShow(that.activityObj, res.data)
					    }
					})
				}

            },
            
            onScrolltolower(){
                that.getActivityList()
            },
            gotoLottery(item) {
                if (item.activityType == 1){
                    uni.navigateTo({
                        url: "/pages/shop/activity/activityLottery?id=" + item.id
                    })
                }
                if (item.activityType == 2){
                    uni.navigateTo({
                        url: "/pages/shop/activity/activityGroupBuy?id=" + item.id
                    })
                }
                if (item.activityType == 3){
                    uni.navigateTo({
                        url: "/pages/shop/activity/activityLike?id=" + item.id
                    })
                }
                if (item.activityType == 4){
                    uni.navigateTo({
                        url: "/pages/shop/activity/activitySignUp?id=" + item.id
                    })
                }
                if (item.activityType == 5){
                    uni.navigateTo({
                        url: "/pages/shop/activity/activityCoupon?id=" + item.id
                    })
                }
                if (item.activityType == 6){
                    uni.navigateTo({
                        url: "/pages/shop/activity/activityHaggle?id=" + item.id
                    })
                }
				if (item.activityType == 7) {
					for (var key in this.redpacketPathMapMixins){
						var value = this.redpacketPathMapMixins[key];
						if (value == item.showType){
							uni.navigateTo({
							    url: "/" + key
							})
						}
					}
				}
            },
            /**
              * @description: 列表中添加数据
              * @param {number} id   u-tabs-swiper的当前ID
              * @param {list}  列表
              * @return void
              */
            pushListShow(srcObj, pushlist) {
                if (pushlist && pushlist.length > 0) {
                    for (let i = 0; i < pushlist.length; i++) {
                        pushlist[i].startTime = utils.formatTime(pushlist[i].startTime, 'yyyy-MM-dd')
                        pushlist[i].endTime = utils.formatTime(pushlist[i].endTime, 'yyyy-MM-dd')
                        srcObj.list.push(pushlist[i])
                    }
                    srcObj.pageIndex++;
                    
                    if (pushlist.length == 10) {
                        srcObj.loadStatus = "loadmore"
                    } else {
                        srcObj.loadStatus = "nomore"
                    }
                } else {
                    srcObj.loadStatus = "nomore"
                }            
            },
            
            //----清空列表
            clearListShow(srcObj) {
				srcObj.curPageIndex = 0;
                srcObj.pageIndex = 1;
                srcObj.list.splice(0, srcObj.list.length)
            },
          
        }
    };
</script>

<style lang="scss">
    page{
        background-color: #f3f3f3;
    }
    .container {
        width: 750rpx;
        background-color: #f3f3f3;
        padding-top: 35rpx;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .activityItem {
        width: 714rpx;
        // height: ;
        background-color: #ffffff;
        margin-bottom: 24rpx;
        position: relative;
        box-shadow: 2rpx 2rpx 8rpx 4rpx #EEEEEE;
        border-radius: 20rpx;
        overflow: hidden;

        .top {
            width: 100%;
            height: 240rpx;
        }

        .bottom {
            width: 100%;
            height: 150rpx;
            background-color: #ffffff;
            display: flex;
            justify-content: space-between;
            align-items: center;

            .left {
                margin-left: 30rpx;
                .title {
                    width: 400rpx;
                    font-size: 32rpx;
                    font-weight: normal;
                    font-stretch: normal;
                    line-height: 40rpx;
                    letter-spacing: 0rpx;
                    color: #333333;
                }

                .introduce {
                    margin-top: 20rpx;
                    width: 400rpx;
                    font-size: 24rpx;
                    line-height: 33rpx;
                    color: #999999;
                }

                .timeOut {
                    max-width: 400rpx;
                    margin-top: 26rpx;
                    height: 24rpx;
                    font-family: MicrosoftYaHei;
                    font-size: 24rpx;
                    font-weight: normal;
                    font-stretch: normal;
                    line-height: 24rpx;
                    letter-spacing: 0rpx;
                    color: #fe8140;
                }
            }

            .right {
                margin-right: 30rpx;
                display: flex;
                flex-direction: column;
                align-items: flex-end;

                .status {
                    width: 180rpx;
                    height: 64rpx;
                    border-radius: 32rpx;
                    line-height: 64rpx;
                    text-align: center;
                    padding: 0 30rpx;
                    font-size: 28rpx;
                }

                .statusEn {
                    background-color: #F6784C;
                    color: #ffffff;
                }

                .statusDis {
                    background-color: #b2b2b2;
                    color: #e8e8e8;
                }
            }
        }
    }
</style>
